<template>
    <div class="manage">
        <div class="manage-header">
            <!-- 搜索表单 -->
            <el-form :inline="true" :model="search">
                <el-form-item>
                    <el-input clearable size="mini" placeholder="帖子内容" v-model="search.content"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" size="mini" @click="getList">查询</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="common-tabel">
            <el-table stripe height="100%" border :data="tableData" style="width: 100%" v-loading="loading" size="mini">
                <el-table-column type="expand">
                    <template slot-scope="scope">
                        <el-table stripe border :data="scope.row.sub_comments" style="width: 100%" size="mini">
                            <el-table-column prop="content" label="回复内容" align="center">
                            </el-table-column>
                            <el-table-column prop="nickname" label="" align="center">
                                <template slot-scope="scope">
                                    {{ scope.row.nickname }} 回复 {{ scope.row.target.nickname }}
                                </template>
                            </el-table-column>
                            <el-table-column prop="created" label="回复时间" align="center">
                            </el-table-column>
                            <el-table-column prop="action" label="操作" align="center" width="80px">
                                <template slot-scope="scope">
                                    <el-button type="danger" size="mini" @click="handleDelete(scope.row)">删除</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </template>
                </el-table-column>
                <el-table-column prop="title" label="帖子内容" align="center">
                </el-table-column>
                <el-table-column prop="nickname" label="评论者昵称" align="center">
                </el-table-column>
                <el-table-column prop="content" label="评论内容" align="center">
                </el-table-column>
                <el-table-column prop="created" label="评论时间" align="center">
                </el-table-column>
                <el-table-column prop="action" label="操作" align="center" width="80px">
                    <template slot-scope="scope">
                        <el-button type="danger" size="mini" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
    </div>
</template>
<script>
import { commentList, commentDelete } from '@/api/postComment';
export default {
    data() {
        return {
            tableData: [],
            search: {
                content: '',
                name: ''
            },
            loading: false,
        }
    },
    methods: {
        // 删除
        handleDelete(row) {
            this.$confirm('确定删除吗?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                commentDelete({ id: row.id }).then(() => {
                    this.$message({
                        type: 'success',
                        message: '删除成功!'
                    });
                    this.getList()
                })

            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
        // 获取列表数据
        getList() {
            this.loading = true;
            commentList({ content: this.search.content }).then((data) => {
                this.tableData = data.result
                this.loading = false;
            })
        },
    },
    mounted() {
        this.getList()
    }
}
</script>
<style lang="less" scoped>
.manage {

    height: 100%;

    .manage-header {
        display: flex;
        justify-content: end;
        align-items: center;
        margin-bottom: 10px;

        .el-form-item {
            margin-bottom: 0;
        }

        /deep/.el-form-item__content {
            line-height: 0;
        }
    }

    .common-tabel {
        position: relative;
        height: calc(100% - 62px);
    }
}
</style>@/api/postComment.js